package com.szqhyxj.youxiangju.biz.personalInformation;

import android.app.Activity;
import android.content.Intent;
import android.net.Uri;
import android.os.Bundle;
import android.support.annotation.Nullable;
import android.view.View;
import android.widget.LinearLayout;
import android.widget.TextView;
import android.widget.Toast;

import com.szqhyxj.youxiangju.BaseActivity;
import com.szqhyxj.youxiangju.R;
import com.szqhyxj.youxiangju.biz.card.addCard.BindCardActivity;
import com.szqhyxj.youxiangju.biz.documentphoto.DocumentPhotoActivity;
import com.szqhyxj.youxiangju.biz.policy.PolicyActivity;
import com.szqhyxj.youxiangju.sys.components.HeadportraitView;
import com.szqhyxj.youxiangju.sys.components.NavigationBar;

import butterknife.BindView;
import butterknife.ButterKnife;
import butterknife.OnClick;

/**
 * Created by leung on 2018/10/30.
 */

public class PersonalInformationActivity extends BaseActivity implements PersonalInformationContract.View ,NavigationBar.NavigationBarListener{
    PersonalInformationContract.Presenter presenter;
    @BindView(R.id.personalavatar)
    HeadportraitView personalavatar;
    @BindView(R.id.personalname)
    TextView personalname;
    @BindView(R.id.personalcardIid)
    TextView personalcardIid;
    @BindView(R.id.personalphone)
    TextView personalphone;
    @BindView(R.id.invitenamname)
    TextView invitenamname;
    @BindView(R.id.invitenamearea)
    LinearLayout invitenamearea;
    @BindView(R.id.decumentphoto)
    LinearLayout decumentphoto;
    @BindView(R.id.policying)
    TextView policying;
    @BindView(R.id.policyarea)
    LinearLayout policyarea;
    @BindView(R.id.navigationBar)
    NavigationBar navigationBar;

    public static void start(Activity activity) {
        Intent intent = new Intent();
        intent.setClass(activity, PersonalInformationActivity.class);
        activity.startActivity(intent);
    }

    @Override
    protected void onCreate(@Nullable Bundle savedInstanceState) {
        super.onCreate(savedInstanceState);
        setContentView(R.layout.activity_personal_information);
        ButterKnife.bind(this);
        presenter = new PersonalInformationPresenter(this);
        presenter.loadInformation();
        navigationBar.setNavigationBarListener(this);
    }

    @Override
    public void showUsername(String s) {
        personalname.setText(s);
    }

    @Override
    public void showIdcardno(String s) {
        personalcardIid.setText(s);
    }

    @Override
    public void showUserphone(String useraccount) {
        personalphone.setText(useraccount);
    }

    @Override
    public void showInvitenamname(String s) {
        invitenamname.setText(s);
    }

    @Override
    public void showPolicying(String policy) {
        policying.setText(policy);
    }

    @Override
    public void navToTelephone(String s) {
        Intent intent = new Intent(Intent.ACTION_DIAL);
        Uri data = Uri.parse("tel:" + s);
        intent.setData(data);
        startActivity(intent);
    }

    @Override
    public void navToPolicy() {
        PolicyActivity.start(this);
    }

    @Override
    public void navToDecumentphoto() {
        DocumentPhotoActivity.start(this);
    }

    @Override
    public void showToast(String s) {
        Toast.makeText(this,s,Toast.LENGTH_LONG).show();
    }

    @Override
    public void navtoaddCard() {
        BindCardActivity.start(this);
    }

    @OnClick({ R.id.decumentphoto, R.id.policyarea})
    public void onClick(View view) {
        switch (view.getId()) {

            case R.id.decumentphoto:
                navToDecumentphoto();
                break;
            case R.id.policyarea:
                if (policying.getText().toString().equals("未投保")){
                 //   BindCardActivity.start(this);
                }else{
                    navToPolicy();
                }

                break;
        }
    }

    @Override
    public void navigationLeft() {
        finish();
    }

    @Override
    public void navigationRight() {

    }
}
